/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.middleware.rabbitmq.gen.handler.impl;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.middleware.rabbitmq.gen.EnumGenHandler;
import org.jeecg.modules.middleware.rabbitmq.gen.handler.IGenMqHandle;
import org.jeecg.modules.wlhy.report.ShippingNoteApiAlct56Service;
import org.jeecg.modules.wlhy.report.ShippingNoteTosApiService;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 创建运单-队列消息接收方法
 *
 * @author duanlikao
 * @created 2022/3/30
 */
@Service
@Slf4j
public class ShippingCreateHandler implements IGenMqHandle {

    private static final Logger LOGGER = LoggerFactory.getLogger(ShippingCreateHandler.class);


    @Autowired
    private ShippingNoteApiAlct56Service shippingNoteApiAlct56Service;

    @Autowired
    private ShippingNoteTosApiService shippingNoteTosApiService;

    @Override
    public String getHandlerName() {
        return EnumGenHandler.SHIPPING_CREATE.getHandlerName();
    }

    @Override
    public void handle(String channel , String msg) {
        try {
            HyShippingNote hyShippingNote =  JSONObject.parseObject(msg, HyShippingNote.class);
            //陆交开放平台 创建运单
//            if("Alct56".equals(channel) &&  "1".equals(hyShippingNote.getAlctIdentification())){
//                shippingNoteApiAlct56Service.createShippingNote(hyShippingNote);
//                log.info("辽宁税务创建运单->{}", JSONUtil.toJsonStr(hyShippingNote));
//            }
            //快货运平台 创建运单
            if("TosApi".equals(channel) && "1".equals(hyShippingNote.getTosIdentification())){
                shippingNoteTosApiService.waybillCreate(hyShippingNote);
            }

        } catch (Exception e) {
            LOGGER.error("[消费消息队列-创建运单-数据失败，失败信息:{}]", e.getMessage());
        }
    }
}
